#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>

//线段树 + 离散化
using namespace std;
using LL = long long;
const int N = 4e4 + 10, M = 2 * N;

struct Node
{
    LL l, r, sum, add;
}node[M * 4];

struct Query{
    int l, r, h;

    bool operator<(const Query& W)const{
        return h < W.h;
    }
}query[N];

int n;
vector<int> nums;

int find(int x){
    return lower_bound(nums.begin(), nums.end(), x) - nums.begin();
}

void pushup(int u){
    node[u].sum = node[u << 1].sum + node[u << 1 | 1].sum;
}

void pushdown(Node& root, Node& left, Node& right){
    if(root.add){
        left.sum = (LL)(nums[left.r + 1] - nums[left.l]) * root.add;
        left.add = root.add;
        right.sum = (LL)(nums[right.r + 1] - nums[right.l]) * root.add;
        right.add = root.add;
        root.add = 0;
    }
}

void pushdown(int u){
    pushdown(node[u], node[u << 1], node[u << 1 | 1]);
}



void build(int u, int l, int r){
    node[u] = {l, r, 0, 0};
    if(l == r) return;

    int mid = l + r >> 1;
    build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
}

void modify(int u, int l, int r, int k){
    if(node[u].l >= l && node[u].r <= r){
        node[u].sum = (LL)(nums[node[u].r + 1] - nums[node[u].l]) * k;
        node[u].add = k;
    }else{
        pushdown(u);
        int mid = (node[u].l + node[u].r) >> 1;
        if(l <= mid) modify(u << 1, l, r, k);
        if(r > mid) modify(u << 1 | 1, l, r, k);
        pushup(u);
    }
}


int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);

    scanf("%d", &n);
    int l, r, h;
    for(int i = 0; i < n; i ++){
        scanf("%d%d%d", &l, &r, &h);
        query[i] = {l, r, h};
        nums.push_back(l);
        nums.push_back(r);
    }

    sort(query, query + n);
    sort(nums.begin(), nums.end());
    nums.erase(unique(nums.begin(), nums.end()), nums.end());



    build(1, 0, nums.size() - 2);

    for(int i = 0; i < n; i ++){
        int l = find(query[i].l), r = find(query[i].r) - 1, h = query[i].h;

        modify(1, l, r, h);
    }

    printf("%lld\n", node[1].sum);


    return 0;
}